<!DOCTYPE html>
<html lang="en">
<head>
		<title>three.js webgl - effects - peppers ghost</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
				body {
						background: #777;
						padding: 0;
						margin: 0;
						font-weight: bold;
						overflow: hidden;
				}

				#info {
						position: absolute;
						top: 0px;
						width: 100%;
						color: #ffffff;
						padding: 5px;
						font-family: Monospace;
						font-size: 13px;
						text-align: center;
						z-index: 1000;
				}

				a {
						color: #ffffff;
				}

				#oldie a {
						color: #da0
				}
		</style>
</head>

<body>
<div id="info"><a href="http://threejs.org" target="_blank">three.js</a> - <a href="https://en.wikipedia.org/wiki/Pepper%27s_ghost">peppers ghost effect</a> demo <br />
		<a href="http://www.instructables.com/id/Reflective-Prism/?ALLSTEPS" target="_blank">basic instructions for building the reflective prism</a></div>

<script src="../build/three.js"></script>

<script src="js/effects/PeppersGhostEffect.js"></script>

<script src="js/Detector.js"></script>

<script>

		if ( ! Detector.webgl ) Detector.addGetWebGLMessage();

		var container;

		var camera, scene, renderer, effect;
		var group;

		init();
		animate();

		function init() {

				container = document.createElement( 'div' );
				document.body.appendChild( container );

				camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 100000 );

				scene = new THREE.Scene();

				group = new THREE.Group();
				scene.add( group );

				// Cube

				var geometry = new THREE.BoxGeometry( 1, 1, 1 );

				for ( var i = 0; i < geometry.faces.length; i += 2 ) {

						var hex = Math.random() * 0xffffff;
						geometry.faces[ i ].color.setHex( hex );
						geometry.faces[ i + 1 ].color.setHex( hex );

				}

				var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, overdraw: 0.5 } );

				for ( var i = 0; i < 10; i ++ ) {

					var cube = new THREE.Mesh( geometry, material );
					cube.position.x = Math.random() * 2 - 1;
					cube.position.y = Math.random() * 2 - 1;
					cube.position.z = Math.random() * 2 - 1;
					cube.scale.multiplyScalar( Math.random() + 0.5 );
					group.add( cube );

				}

				renderer = new THREE.WebGLRenderer();
				renderer.setPixelRatio( window.devicePixelRatio );
				container.appendChild( renderer.domElement );

				effect = new THREE.PeppersGhostEffect( renderer );
				effect.setSize( window.innerWidth, window.innerHeight );
				effect.cameraDistance = 5;

				window.addEventListener( 'resize', onWindowResize, false );

		}

		function onWindowResize() {

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

				effect.setSize( window.innerWidth, window.innerHeight );

		}

		function animate() {

				requestAnimationFrame( animate );

				render();

		}

		function render() {

				camera.lookAt( scene.position );

				group.rotation.y += 0.01;

				effect.render( scene, camera );

		}


</script>

</body>
</html>
